package com.kpx.app.wigdet;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

import com.kpx.app.R;

/**
 * 改变定位位置Dialog
 *
 * @author
 */
public class DialogChangeLocation extends BaseDialog implements View.OnClickListener {
    private OnChangeLocationButtonClickListener onChangeLocationButtonClickListener;
    private OnRetainButtonClickListener onRetainButtonClickListener;
    private Button changeLocationBtn;
    private Button retainLocationBtn;
    private View noLogerRemindCheckBoxContainer;
    private CheckBox noLongerRemindCheckBox;

    public DialogChangeLocation(Context context, OnChangeLocationButtonClickListener onChangeLocationButtonClickListener, OnRetainButtonClickListener onRetainButtonClickListener) {
        super(context);
        setContent();
        setOnChangeLocationButtonClickListener(onChangeLocationButtonClickListener);
        setOnRetainButtonClickListener(onRetainButtonClickListener);
    }

    private void setContent() {
        setContentView(R.layout.dialog_change_location_layout);
        changeLocationBtn = (Button) findViewById(R.id.changeLocationBtn);
        changeLocationBtn.setOnClickListener(this);
        retainLocationBtn = (Button) findViewById(R.id.retainLocationBtn);
        retainLocationBtn.setOnClickListener(this);
        noLogerRemindCheckBoxContainer = findViewById(R.id.noLogerRemindCheckBoxContainer);
        noLogerRemindCheckBoxContainer.setOnClickListener(this);
        noLongerRemindCheckBox = (CheckBox) findViewById(R.id.noLongerRemindCheckBox);
    }

    /**
     * 切换位置
     */
    public void setOnChangeLocationButtonClickListener(OnChangeLocationButtonClickListener listener) {
        this.onChangeLocationButtonClickListener = listener;
    }

    /**
     * 保留位置
     */
    public void setOnRetainButtonClickListener(OnRetainButtonClickListener listener) {
        this.onRetainButtonClickListener = listener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.noLogerRemindCheckBoxContainer:
                if (noLongerRemindCheckBox.isChecked()) {
                    noLongerRemindCheckBox.setChecked(false);
                } else {
                    noLongerRemindCheckBox.setChecked(true);
                }
                break;
            case R.id.changeLocationBtn:
                if (onChangeLocationButtonClickListener != null)
                    onChangeLocationButtonClickListener.onChangeLoactionButtonClick(noLongerRemindCheckBox.isChecked(), this);
                break;
            case R.id.retainLocationBtn:
                if (onRetainButtonClickListener != null)
                    onRetainButtonClickListener.onRetainButtonClick(noLongerRemindCheckBox.isChecked(), this);
                break;
        }
    }

    /**
     * 确定监听器
     */
    public interface OnChangeLocationButtonClickListener {
        void onChangeLoactionButtonClick(boolean noLongerRemind, Dialog dialog); // 点击切换位置按钮
    }

    /**
     * 取消监听器
     */
    public interface OnRetainButtonClickListener {
        void onRetainButtonClick(boolean noLongerRemind, Dialog dialog); // 点击保留位置按钮
    }
}
